clear all
set more off
set scheme s2color
cd ""

use "sample.dta", clear

****************
* Subfigure (1)
****************

* Generate time-to-event dummies

tab rel_time, gen(rel_w)

forvalue i = 1/31 {
local j = `i' - 11
label var rel_w`i' "`j'"
}

* Generate interaction terms between time-to-event dummies and faction

forvalue i = 1/31 {
gen rel_w`i'_D = rel_w`i' * faction
}

forvalue i = 1/31 {
local j = `i' - 11
label var rel_w`i'_D "`j'"
}

qui: reghdfe in_confn14 rel_w1_D-rel_w9_D rel_w11_D-rel_w31_D rel_w10_D treat_csm wdsp temp prcp, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)
est store in_confn14_ddd

#delimit ;
coefplot in_confn14_ddd, vertical recast(scatter) keep(rel_w*_D) omitted
         order(rel_w1_D rel_w2_D rel_w3_D rel_w4_D rel_w5_D rel_w6_D rel_w7_D rel_w8_D rel_w9_D rel_w10_D
               rel_w11_D rel_w12_D rel_w13_D rel_w14_D rel_w15_D rel_w16_D rel_w17_D rel_w18_D rel_w19_D rel_w20_D 
               rel_w21_D rel_w22_D rel_w23_D rel_w24_D rel_w25_D rel_w26_D rel_w27_D rel_w28_D rel_w29_D rel_w30_D rel_w31_D)
         msymbol(Oh) mcolor(blue) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(blue))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash)) yscale(range(-0.8 0.22))
         ylabel(-0.8(0.2)0.2, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr

****************
* Subfigure (2)
****************

qui: reghdfe d_movewithin rel_w1_D-rel_w9_D rel_w11_D-rel_w31_D rel_w10_D treat_csm wdsp temp prcp, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction i.prov_code#c.time2#i.faction) cluster(time)
est store d_movewithin_ddd

#delimit ;
coefplot d_movewithin_ddd, vertical recast(scatter) keep(rel_w*_D) omitted
         order(rel_w1_D rel_w2_D rel_w3_D rel_w4_D rel_w5_D rel_w6_D rel_w7_D rel_w8_D rel_w9_D rel_w10_D
               rel_w11_D rel_w12_D rel_w13_D rel_w14_D rel_w15_D rel_w16_D rel_w17_D rel_w18_D rel_w19_D rel_w20_D 
               rel_w21_D rel_w22_D rel_w23_D rel_w24_D rel_w25_D rel_w26_D rel_w27_D rel_w28_D rel_w29_D rel_w30_D rel_w31_D)
         msymbol(Oh) mcolor(blue) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(blue))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash)) yscale(range(-11.5 5.5))
         ylabel(-10(5)5, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr

****************
* Subfigure (3)
****************

qui: reghdfe bdindexS7_std rel_w1_D-rel_w9_D rel_w11_D-rel_w31_D rel_w10_D treat_csm wdsp temp prcp, absorb(i.city_code#i.faction i.time#i.faction i.prov_code#c.time#i.faction) cluster(time)
est store bdindexS7_std_ddd

#delimit ;
coefplot bdindexS7_std_ddd, vertical recast(scatter) keep(rel_w*_D) omitted
         order(rel_w1_D rel_w2_D rel_w3_D rel_w4_D rel_w5_D rel_w6_D rel_w7_D rel_w8_D rel_w9_D rel_w10_D
               rel_w11_D rel_w12_D rel_w13_D rel_w14_D rel_w15_D rel_w16_D rel_w17_D rel_w18_D rel_w19_D rel_w20_D 
               rel_w21_D rel_w22_D rel_w23_D rel_w24_D rel_w25_D rel_w26_D rel_w27_D rel_w28_D rel_w29_D rel_w30_D rel_w31_D)
         msymbol(Oh) mcolor(blue) pstyle(p4) ciopts(recast(rcap) lpattern(dash) lcolor(blue))
         xtitle("Relative days to Community Stringent Measures", axis(1)) 
         xlabel(, valuelabel axis(1) labsize(small) tlength(0.8))
         yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
         xline(10, lcolor(cranberry) lwidth(thin) lpattern(dash)) yscale(range(-0.225 0.6))
         ylabel(-0.2(0.2)0.6, grid axis(1) labsize(small) tlength(0.8) glwidth(vthin) nogextend) 
         graphregion(fcolor(white) color(white) icolor(white) ilstyle(p1box) margin(small)) plotregion(margin(vsmall));
#delimit cr

